package cn.hongwei.controller;

import cn.hongwei.result.R;
import cn.hongwei.service.FileService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.concurrent.TimeUnit;

/**
 * @author Great
 * @email 1224028994@qq.com
 */
@CrossOrigin
@RestController
@RequestMapping("/oss")
public class UploadController {

    @Autowired
    private FileService fileService;

    //上传
    @PostMapping("/upload")
    public R uploadAvatar(MultipartFile file,String module){
        String path = fileService.upload(file, module);
        //返回上传成功的图片地址
        return R.ok().data("path" , path);
    }

    //删除阿里云文件
    @DeleteMapping("/delete")
    public R delete(String path,String module){
        try {
            Thread.sleep(3000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        fileService.delete(path,module);
        return R.ok();
    }
}
